package com.ming.TreadPool;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Auther: tangC
 * @Date: 2020/7/9 15:05
 * @Description: 自定义饱和处理方式
 */
public class ThreadHandler implements RejectedExecutionHandler {

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (!executor.isShutdown()){
            try {
                Thread.sleep(5000);
                executor.execute(r);
            }catch (Exception e){

            }
        }else {
            throw new RejectedExecutionException("Executor has been shut down");
        }

    }
}
